const { DataTypes, Model } = require('sequelize')
const { sequelize } = require('./index')
const { User } = require('./user')

class Article extends Model { }

Article.init({
  title: {
    type: DataTypes.STRING,
  },
  content: {
    type: DataTypes.STRING,
  },
  uid: {
    type: DataTypes.INTEGER
  }
}, {
  sequelize, // 我们需要传递连接实例
  // modelName: 'User' // 我们需要选择模型名称
  tableName: 't_article',
})

User.hasMany(Article, { as: 'Articles', foreignKey: 'uid' })
Article.belongsTo(User, { as: 'User', foreignKey: 'uid' })

module.exports = {
  Article,
}